package com.yidu.BusinessData.controller;

import com.yidu.BusinessData.entity.Broker;
import com.yidu.BusinessData.entity.TradingSeats;
import com.yidu.BusinessData.service.TradingSeatsServce;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * 席位控制器
 * @author zhouhongyu
 * @since 2022/8/16
 * @version 1.0
 */
@RestController
public class TradingSeatsController {
    @Autowired
    private TradingSeatsServce tradingSeatsServce;//自动装配

    /**
     * 条件查询
     * @param seatName
     * @param page
     * @param limit
     * @return
     */
    @RequestMapping("selectTradingSeats")
    public Map selectTradingSeats(String seatName,String seatType,int page,int limit){
        System.out.printf("这是分页加查询的控制器！");
        System.out.println("seatType============="+seatType);
        if (seatName == null){
            seatName="";
        }
        List<TradingSeats> tradingSeatsList =
                tradingSeatsServce.selectTradingSeats(seatName,seatType, page, limit);
        for (TradingSeats e:
             tradingSeatsList) {
            System.out.println(e);
        }
        int i = tradingSeatsServce.selectCount();
        Map map = new HashMap<>();
        map.put("code",0);
        map.put("msg","");
        map.put("count",i);
        map.put("data",tradingSeatsList);
        return map;
    }

    /**
     * 增加数据
     * @param seats
     * @return
     */
    @RequestMapping("/insertTradingSeats")
    public String insertTradingSeats(TradingSeats seats){
        System.out.println("这是增加数据的控制器");
        int i = tradingSeatsServce.insertTradingSeats(seats);
        if (i == 1){
            return "增加成功";
        }else{
            return "增加数百";
        }
    }

    /**
     * 删除数据
     * @param seatId
     * @return
     */
    @RequestMapping("/deleteTradingSeats")
    public int deleteTradingSeats(String seatId){
        System.out.println("这是删除数据的控制器");
        int i = tradingSeatsServce.deleteTradingSeats(seatId);
        return i;
    }

    /**
     * 修改数据
     * @param tradingSeats
     * @return
     */
    @RequestMapping("/updateTradingSeats")
    public String updateTradingSeats(TradingSeats tradingSeats){
        System.out.println("这是修改数据的控制器");
        int i = tradingSeatsServce.updateTradingSeats(tradingSeats);
        if (i == 1){
            return "修改成功";
        }else{
            return "修改失败";
        }
    }

    /**
     * 下拉表格控制器
     * @return
     */
    @RequestMapping(value = "selectBroker1")
    public Map selectBroker1(){
        List<Broker> brokers = tradingSeatsServce.selectBroker1();
        int count = tradingSeatsServce.selectCount();
        Map map = new HashMap();
        map.put("msg","");
        map.put("code","0");
        map.put("count",count);
        map.put("data",brokers);
        return map;
    }
}
